package org.atfeihu.springcloud.alibaba.controller;

import org.atfeihu.springcloud.alibaba.domain.CommonResult;
import org.atfeihu.springcloud.alibaba.service.AccountService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author wangfeihu
 * @create 2021/9/12 19:51
 */
@RestController
public class AccountController {

    @Resource
    private AccountService accountService;

    @PostMapping("/account/decrease")
    public CommonResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money) {
        accountService.decrease(userId, money);
        try { TimeUnit.SECONDS.sleep(10); }catch (Exception e) {e.printStackTrace();}
        return new CommonResult(200, "账户余额扣减成功");
    }
}
